<?php

class PublicController extends CommonsController
{

    public $layout='/layouts/column2';
    public function actionGetMap()
    {
        Yii::app()->clientScript->registerScriptFile($this->adminPath . '/js/jquery.min.js',CClientScript::POS_HEAD);
        $this->layout = '/layouts/dialog';
        $this->render('get_map');
    }
    public function actionGetArticleRelated(){
        Yii::app()->clientScript->registerScriptFile($this->adminPath . '/js/jquery.min.js',CClientScript::POS_HEAD);
        $this->layout = '/layouts/dialog';
        $criteria = new CDbCriteria;
        $city_id = Yii::app()->request->getParam('city');
        $criteria->addCondition('is_show=1','AND');
        $criteria->addCondition('city_id=:city_id','AND');
        if(XUtils::method() == 'POST'){
            $title = CHtml::encode($_POST['title']);
            $criteria->addSearchCondition('title',$title,true,'AND');
        }
        $criteria->params[':city_id']=$city_id;
        $criteria->order = 'listorder DESC,id DESC';
        $count = Article::model()->count($criteria);
        $pager = new CPagination($count);
        $pager->pageSize = 10;
        $pager->applyLimit($criteria);
        $list = Article::model()->findAll($criteria);
        $this->render('get_article_related',array('list'=>$list,'pages'=>$pager));
    }
    public function actionGetRelated(){
        Yii::app()->clientScript->registerScriptFile($this->adminPath . '/js/jquery.min.js',CClientScript::POS_HEAD);
        $this->layout = '/layouts/dialog';
        $criteria = new CDbCriteria;
        $type = Yii::app()->request->getParam('type');
        $city_id = Yii::app()->request->getParam('city');
        if($type=='destination'){
            //查询
            $criteria->addCondition('type=:type1','OR');
            $criteria->addCondition('type=:type2','OR');
            $criteria->addCondition('type=:type3','OR');
            $criteria->addCondition('is_show=1','AND');
            $criteria->addCondition('city_id=:city_id','AND');
            if(XUtils::method() == 'POST'){
                $title = CHtml::encode($_POST['title']);
                $criteria->addSearchCondition('title',$title,true,'AND');
            }
            $criteria->params[':type1']='酒店';
            $criteria->params[':type2']='农家院';
            $criteria->params[':type3']='度假村';
            $criteria->params[':city_id']=$city_id;
        }elseif($type=='hotel'){
            //查询
            $criteria->addCondition('type=:type1','OR');
            $criteria->addCondition('is_show=1','AND');
            $criteria->addCondition('city_id=:city_id','AND');
            if(XUtils::method() == 'POST'){
                $title = CHtml::encode($_POST['title']);
                $criteria->addSearchCondition('title',$title,true,'AND');
            }
            $criteria->params[':type1']='景点';
            $criteria->params[':city_id']=$city_id;
        }elseif($type=='farm'){
            //查询
            $criteria->addCondition('type=:type1','OR');
            $criteria->addCondition('is_show=1','AND');
            $criteria->addCondition('city_id=:city_id','AND');
            if(XUtils::method() == 'POST'){
                $title = CHtml::encode($_POST['title']);
                $criteria->addSearchCondition('title',$title,true,'AND');
            }
            $criteria->params[':type1']='景点';
            $criteria->params[':city_id']=$city_id;
        }elseif($type=='resort'){
            //查询
            $criteria->addCondition('type=:type1','OR');
            $criteria->addCondition('is_show=1','AND');
            $criteria->addCondition('city_id=:city_id','AND');
            if(XUtils::method() == 'POST'){
                $title = CHtml::encode($_POST['title']);
                $criteria->addSearchCondition('title',$title,true,'AND');
            }
            $criteria->params[':type1']='景点';
            $criteria->params[':city_id']=$city_id;
        }elseif($type=='pick'){
            //查询
            $criteria->addCondition('type!=:type1','OR');
            $criteria->addCondition('is_show=1','AND');
            $criteria->addCondition('city_id=:city_id','AND');
            if(XUtils::method() == 'POST'){
                $title = CHtml::encode($_POST['title']);
                $criteria->addSearchCondition('title',$title,true,'AND');
            }
            $criteria->params[':type1']='采摘园';
            $criteria->params[':city_id']=$city_id;
        }elseif($type=='weekly'){
            //查询
            $criteria->addCondition('type=:type1','OR');
            $criteria->addCondition('is_show=1','AND');
            $criteria->addCondition('city_id=:city_id','AND');
            if(XUtils::method() == 'POST'){
                $title = CHtml::encode($_POST['title']);
                $criteria->addSearchCondition('title',$title,true,'AND');
            }
            $criteria->params[':type1']='玩点';
            $criteria->params[':city_id']=$city_id;
        }

        $criteria->order = 'listorder DESC,id DESC';
        $count = Article::model()->count($criteria);
        $pager = new CPagination($count);
        $pager->pageSize = 10;
        $pager->applyLimit($criteria);
        $list = Article::model()->findAll($criteria);

        $this->render('get_related',array('list'=>$list,'pages'=>$pager,'type'=>$type));
//        if($type){
//            $criteria->addCondition('category=:category');//公用
//            $criteria->params[':category']=$type;
//        }
//        $criteria->addCondition('type=:type');//公用
//        $criteria->params[':type']='bg';
//        $criteria->order = 'id DESC';
//        $count = ScenePicture::model()->count($criteria);
//        $pager = new CPagination($count);
//        $pager->pageSize = 30;
//        $pager->applyLimit($criteria);
//        $list = ScenePicture::model()->findAll($criteria);
//        $this->render('ajax_scene_pictures',array('list'=>$list,'pages'=>$pager,'type'=>$type));

    }
}